import requests
import re

# --------------- 获取cookie，传递给下个接口  ---------------
# 案例：登录后，访问个人信息页
id = 1
username = 'student'
password = '123456'
vericode = 'shtd'

# 构造 url
url_first = r'http://localhost:8080/bsams/front/login.do'
url_vericode = r'http://localhost:8080/bsams/front/vericode.do'
url_info = r'http://localhost:8080/bsams/front/asset_user/user_info.do'
# 构造 data
data = {
    'taskId': id,
    'loginName': username,
    'password': password,
    'vericode': vericode
}
# 发送请求
resp = requests.get(url_first)
cookies = resp.cookies.get_dict()  # 在这里取
requests.get(url_vericode, cookies=cookies)
requests.post(url_first, data=data, cookies=cookies)
resp = requests.get(url_info, cookies=cookies)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)
